<template>
	<view class="popupBody">
		<view class="title">
			选择售后商品
		</view>
		<view class="shop_body" v-for="(item,index) in listData.goods" :key="index">
			<u-checkbox-group size="45" icon-size="30" :disabled="item.after_sales" active-color="#5062A7"
				style="display: flex;align-items: center;">
				<u-checkbox v-model="item.checked" shape="circle"></u-checkbox>
			</u-checkbox-group>
			<image class="shop_img"  :src="item.goods_cover" mode="aspectFill"></image>
			<view class="shop_title">
				<view class="shop_title_top">
					<view class="shop_title_top_name shenglueh2 ellipsis-2 ">
						{{item.goods_name}}
					</view>
					<view class="shop_title_top_price" style="font-size: 30rpx;font-weight: bold;">
						<span style="font-size: 20rpx;">￥</span>
						<span>{{item.goods_price}}</span>
					</view>
				</view>
				<view class="shop_title_bom JSB">
					<span>{{item.specs}}</span>
					 <text>×{{item.num}}</text>
					<view class="shop_title_bom_state" v-if="item.after_sales==1">售后中</view>
					<view class="shop_title_bom_state" v-if="item.after_sales==2">已退款</view>
				</view>
			</view>
		</view>
		<defaultData v-if="listData.goods.length==0" :imageUrl="imageUrl+'gowuchequesheng.png'" :text="'暂无可售后商品'"
			:width="'335.1rpx'" :height="'192.26rpx'" :marginTop="'80rpx'"></defaultData>
		<view class="shop_bm">

		<view class="" style="margin-left: 24rpx;">
			<u-checkbox-group size="45" icon-size="30" active-color="#5062A7" :disabled="allDisabled"
				style="display: flex;align-items: center;">
				<u-checkbox v-model="allChoose" shape="circle" @change="allChange">全选</u-checkbox>
			</u-checkbox-group>
		</view>


			<view class="shop_bm_btn" @click="toApply ">确认申请</view>
		</view>
	</view>
</template>
<script setup lang="ts">
	import { onLoad, onShow } from '@dcloudio/uni-app'
	import { ref, reactive, defineProps, nextTick,computed } from 'vue'
	import logistics from "@/pagesB/mine/mineStudent/logistics.vue"
	import afterSalesd from "@/components/popup/afterSales.vue"
	import { shopAfterSales, shopAfterSalesDo } from '@/service/api/shop'
	import tools from '@/utils/tools'
	const allChoose = ref(false)
	const props = defineProps({
		listData: {} as any,
		imageUrl: {} as any,
 
	})
	const allDisabled = computed({
		get:()=>{
		let flag=	props.listData.goods.every(t=>{
				return t.after_sales;
			})
			return flag;
		},
		set:()=>{
			
		}
	})


	const allChange = () => {
		if (!allChoose.value) {
			//选中
			props.listData.goods.forEach((item) => {
				if(item.after_sales){
					item.checked = true
				}
				
			})
		} else {
			//取消
			props.listData.goods.forEach((item) => {
				if(item.after_sales){
					item.checked = false
				}
				
			})
		}
	}
	//单选
	const checkChange = () => {
		nextTick(() => {
			allChoose.value = props.listData.goods.every(t => { return t.checked })
		})
	}
	const toApply = () => {
		let flag = false;
		console.log(props.listData);
		props.listData.goods.forEach((t)=>{
			if(t.checked){
				flag = true
			}
		})
		// let flag = props.listData.goods.every(t => {
		// 	return t.checked;
		// })
		if (!flag) {
			tools.showToast('请选择售后商品')
			return
		}

		let goods_ids = []
		props.listData.goods.forEach((item) => {
			goods_ids.push(item.id);
		})
		
		tools.navTo('/pagesB/order/apply/apply?id=' + props.listData.id + '&goods_ids=' + JSON.stringify(goods_ids))
	}
</script>

<style lang="scss" scoped>
	.ellipsis-2 {
		// 注意，不要设置此标签的高度，下方代码设置了行数，会自动根据行数进行计算高度的。

		//文本超出部分以...形式展示
		text-overflow: -o-ellipsis-lastline;
		//整体超出部分隐藏
		overflow: hidden;
		//文本超出部分以...形式展示，同第一行样式代码
		text-overflow: ellipsis;
		//display 块级元素展示
		display: -webkit-box;
		//设置文本行数为2行
		-webkit-line-clamp: 2;
		//设置文本行数为2行
		line-clamp: 2;
		//从上到下垂直排列子元素（设置伸缩盒子的子元素排列方式）
		-webkit-box-orient: vertical;

	}

	.popupBody {
		min-height: 600rpx;
		background-color: #F6F7FB;
		border-radius: 40rpx 40rpx 0rpx 0rpx;
		padding: 30rpx;
		padding-bottom: 190rpx;
		position: relative;

		.title {
			font-size: 32rpx;
			text-align: center;
		}

		.shop_body {
			margin-top: 30rpx;
			background: #FFFFFF;
			border-radius: 20rpx;
			padding: 20rpx;
			display: flex;
			position: relative;

			// align-items: center;
			.chooseF {
				width: 44rpx;
				height: 44rpx;
				border: 2rpx solid #BBBBBB;
				border-radius: 50%;
				margin-top: 50rpx;
			}

			.chooseF2 {
				width: 44rpx;
				height: 44rpx;
				border: 2rpx solid #EEEEEE;
				border-radius: 50%;
				margin-top: 50rpx;
				background-color: #EEEEEE;
			}

			.choose_img {
				width: 44rpx;
				height: 44rpx;
				border: 2rpx solid #FFFFFF;
				margin-top: 50rpx;
			}

			.shop_img {
				width: 140rpx;
				height: 140rpx;
				border-radius: 10rpx;
				// margin-left: 20rpx;
			}

			.shop_title {
				margin-left: 20rpx;

				.shop_title_top {
					display: flex;
					align-items: flex-start;

					.shop_title_top_name {
						width: 280rpx;
						height: 80rpx;
						font-size: 28rpx;
						line-height: 40rpx;
						color: #000000;
					}

					.shop_title_top_price {
						width: 118rpx;
						text-align: right;
						font-size: 24rpx;
						line-height: 40rpx;
						color: #000000;

					 
					}
				}

				.shop_title_bom {
					margin-top: 10rpx;
					font-size: 24rpx;
					color: #888888;

					.shop_title_bom_state {
						// position: absolute;
						right: 30rpx;
						bottom: 28rpx;
						line-height: 50rpx;
						font-size: 24rpx;
						color: #888888;
					}

					text {
						margin-left: 40rpx;
					}
				}

				.JSB {
					display: flex;
					justify-content: space-between;
					align-items: center;
				}
			}
		}

		.shop_bm {
			position: absolute;
			width: 100%;
			height: 160rpx;
			margin: 0 -30rpx;
			padding: 0 30rpx;
			background-color: #FFFFFF;
			bottom: 0;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.shop_bm_all {
				.chooseF {
					width: 44rpx;
					height: 44rpx;
					border: 2rpx solid #BBBBBB;
					border-radius: 50%;
					margin: 0 20rpx;
				}

				.choose_img {
					width: 44rpx;
					height: 44rpx;
					border: 2rpx solid #FFFFFF;
					margin: 0 20rpx;
				}

				display: flex;
				align-items: center;

				.shop_bm_all_text {
					font-size: 28rpx;
					color: #000000;
				}
			}
		}

		.shop_bm_btn {
			width: 400rpx;
			text-align: center;
			background: linear-gradient(90deg, #5062A7 0%, #354678 100%);
			border-radius: 10rpx;
			padding: 26rpx 0;
			color: white;
			font-size: 32rpx;

		}
	}
</style>